package com.showimage.www;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class Showimage extends Activity {
	private Gallery gallery;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  
        setContentView(R.layout.main);
        gallery = (Gallery) findViewById(R.id.gallery);
		gallery.setAdapter(new imageAdapter(this));
    }
}
class imageAdapter extends BaseAdapter {
	private Integer[] mThumbIds = {
            R.drawable.bj, R.drawable.j,
            R.drawable.p, R.drawable.m,
            R.drawable.c1};

	Context context;
	/*File file1 = new File("./sdcard/My photo/");
	File[] files = file1.listFiles();
	List<String> img = new ArrayList<String>();*/

	public imageAdapter(Context c) {
		this.context = c;
		/*for (File f : files) {
			if (f.getPath().endsWith(".jpg")||f.getPath().endsWith(".gif")||f.getPath().endsWith(".png")) {
				img.add(f.getPath());
			}
		}*/

	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mThumbIds.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imag = new ImageView(this.context);
		//imag.setImageURI(Uri.parse(img.get(position)));
		imag.setImageResource(mThumbIds[position]);
		imag.setScaleType(ImageView.ScaleType.FIT_XY);
		imag.setLayoutParams(new Gallery.LayoutParams(
				android.widget.Gallery.LayoutParams.FILL_PARENT,
				android.widget.Gallery.LayoutParams.FILL_PARENT));
		return imag;
	}

	public float getScale(boolean focused, int offset) {
		return Math.max(0, 1.0f / (float) Math.pow(2, Math.abs(offset)));

	}

}